<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" exportUrl="/api/admin/export/withdraw"
        :isHaveAdd="false">
      <template v-slot:table>
        <div class="withdraw_sum">
          <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="allowSelection()">批量通过</el-button>
          <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="rejectSelection()">批量驳回</el-button>
        </div>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>

          <el-table-column label="头像" min-width="70">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="145">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.nickname || "----" }}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{ scope.row.username }}</span>
                </div>
                <div>
                  <span>用户等级：</span>
                  <span class="rat" v-show="scope.row.rating_cn">{{
                    scope.row.rating_cn
                  }}</span>
                </div>
                <div v-if="scope.row.shop_title != ''">
                  <span v-if="scope.row.shop_title != ''">店铺名称：</span>
                  <small v-if="scope.row.shop_title != ''">{{
                    scope.row.shop_title
                  }}</small>
                  <br v-if="scope.row.shop_title != ''" />
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="订单" min-width="153">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>订单号：</span>
                  <span>{{ scope.row.oid }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="金额" min-width="145">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>申请金额：</span>
                  <span>
                    {{ scope.row.money | keepTwoNum }}
                    {{ scope.row.style_cn }}
                  </span>
                </div>
                <div>
                  <span>实提金额：</span>
                  <span>
                    {{ scope.row.real_money | keepTwoNum }}
                    {{ scope.row.style_cn }}
                  </span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="时间" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>申请时间：</span>
                  <span>{{ scope.row.created_time | getTimeFormat }}</span>
                </div>
                <div v-show="scope.row.update_time != scope.row.created_time">
                  <span>处理时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div>
                <!-- <div>
                                    <span>完成时间：</span>
                                    <span>{{scope.row.created_time_cn}}</span>
                </div>-->
              </div>
            </template>
          </el-table-column>

          <el-table-column label="状态" min-width="145">
            <template slot-scope="scope">
              <div class="tab_div">
                <div class="mar_bottom_5">
                  <span>提现账户：</span>
                  <span class="rat tx">{{ scope.row.style_cn }}</span>
                </div>
                <div class="mar_bottom_5">
                  <span>提现方式：</span>
                  <span class="rat tx">{{ scope.row.pay }}</span>
                </div>
                <div>
                  <span>提现状态：</span>
                  <el-tag effect="dark" style="color:#fff" type="success" v-if="scope.row.status == '1'">{{ scope.row.status_cn }}</el-tag>
                  <el-tag effect="dark" style="color:#fff" type="danger" v-else-if="scope.row.status == '2'">{{ scope.row.status_cn }}</el-tag>
                  <el-tag effect="dark" style="color:#fff" type v-else>{{
                    scope.row.status_cn
                  }}</el-tag>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" min-width="80">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="showEditDialog(scope.row.id)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <div class="withdraw_sum">
          <p>
            <span>总佣金：</span>
            {{ list.count_ar.all_money || 0 }}
          </p>
          <p>
            <span>申请中：</span>
            {{ list.count_ar.apply_money || 0 }}
          </p>
          <p>
            <span>已提现：</span>
            {{ list.count_ar.apply_success || 0 }}
          </p>
          <p>
            <span>未提现：</span>
            {{ list.count_ar.apply_false || 0 }}
          </p>
        </div>
      </template>
    </tableComponents>

    <WithdrawYeEdit @parent="reload" :show.sync="show" :editId="editId" :clickNum="clickNum"></WithdrawYeEdit>

    <el-dialog :close-on-click-modal="false" title="提现" :modal-append-to-body="false" :visible.sync="visible" class="tl size_13" width="800px">
      <div v-for="(item, i) in arr" :key="i">
        <br />
        {{ item }}
        <br />
      </div>
      <div class="mar_bottom_15"></div>
    </el-dialog>
  </div>
</template>
<script>
import switchc from "../currency/Swich";
import WithdrawYeEdit from "@/components/user/withdraw_ye_edit.vue";

import HeadTitle from "@/components/currency/HeadTitle.vue";
import tixianSearch from "@/components/currency/tixianSearch.vue";
import { userwithdraw_yeSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data () {
    return {
      userSearchData: userwithdraw_yeSearchData,
      status: "",
      withdraw_sum: {
        all_money: 0,
        apply_money: 0,
        apply_success: 0,
        apply_false: 0
      },
      show: false,
      loading: false,
      list: {
        count_ar: {
          all_money: 0,
          apply_money: 0,
          apply_success: 0,
          apply_false: 0
        },
        data: []
      },
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      multipleSelection: "",
      arr: [],
      visible: false,
      clickNum: 0,
      updataIndex: "",
      searchAll: {},
    };
  },
  components: {
    switchc,
    WithdrawYeEdit,
    HeadTitle,
    tixianSearch
  },
  methods: {
    get_sum () {
      this.$api.getUser.get_withdraw_sum({}).then(res => {
        if (res.data.code == 200) {
          this.withdraw_sum = res.data.result;
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    allowSelection () {
      this.arr = [];
      if (this.multipleSelection.length == 0) {
        this.$message.error("请先选择需要审核的数据");
        return false;
      }
      this.visible = true;

      for (var i = 0; i < this.multipleSelection.length; i++) {
        var data = { id: this.multipleSelection[i]["id"] };
        this.$api.getUser.getWithdrawYeAllow(data).then(res => {
          this.arr.push(res.data.result);
        });
      }
      var aa = this;
      window.setTimeout(function () {
        aa.getNewsAll();
      }, 1000);
    },
    rejectSelection () {
      this.arr = [];
      if (this.multipleSelection.length == 0) {
        this.$message.error("请先选择需要驳回的数据");
        return false;
      }
      this.visible = true;
      var _this = this;
      for (var i = 0; i < this.multipleSelection.length; i++) {
        var data = { id: this.multipleSelection[i]["id"] };
        _this.updataIndex = i;
        this.$api.getUser.getWithdrawYeReject(data).then(res => {
          this.arr.push(res.data.result);
          console.log(_this.updataIndex);
        });
      }

      var aa = this;
      window.setTimeout(function () {
        aa.getNewsAll();
      }, 1000);
    },
    showEditDialog (id) {
      this.show = true;
      this.editId = id;
      this.clickNum++;
    },
    reload (id) {
      this.getNewsAll(1);
    },
    getSearch (obj) {
      this.searchAll = obj;
      this.getNewsAll(1);
    },
    getNewsAll (page) {
      this.loading = true;
      var params = {};
      params = this.searchAll;
      params.page = page;
      params.page_size = this.pagesize;
      this.$api.getUser.getWithdrawYeList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      this.pagesize = val;
      this.getNewsAll(1);
    },
    handleCurrentChange (val) {
      this.currentPage = parseInt(val);
      this.getNewsAll(this.currentPage);
    }
  },
  beforeCreate () { },
  created () {
    this.searchAll.status = this.$route.query.action || "";
    this.status = this.$route.query.action || "";
    this.getNewsAll(1);
  },
  computed: {},
  watch: {
    $route () {
      this.status = this.$route.query.action || "";
    },
    status () {
      this.searchAll.status = this.status;
      this.getNewsAll(1);
    }
  }
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
.withdraw_sum {
  width: 80%;
  margin-bottom: 15px;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}
.withdraw_sum p {
  font-size: 14px;
  line-height: 32px;
  padding-right: 40px;
}
.withdraw_sum span {
  font-size: 14px;
  font-weight: bold;
}
</style>
